package org.apache.ibatis.executor.resultset;

import org.apache.ibatis.BaseDataTest;
import org.apache.ibatis.domain.blog.Author;
import org.apache.ibatis.domain.blog.mappers.AuthorMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class DefaultResultSetHandlerTest3 {
    private Configuration configuration;
    private SqlSessionFactory sqlSessionFactory;

    @BeforeAll
    public void createConfiguration() throws Exception {
        BaseDataTest.createBlogDataSource();

        final String resource = "org/apache/ibatis/builder/MapperConfig.xml";
        final Reader reader = Resources.getResourceAsReader(resource);
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        configuration = sqlSessionFactory.getConfiguration();
    }

    @Test
    public void test() {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        AuthorMapper mapper = sqlSession.getMapper(AuthorMapper.class);
        Author author = mapper.selectAuthor(101);
        System.out.println(author);
    }

}
